#include "StdAfx.h"
#include "DocumentsWrapper.h"


CDocumentsWrapper::CDocumentsWrapper(CString filename)
{
	m_DLLhInstance = NULL ;				// no DLL loaded
	m_FileName = _T("") ;					// no filename

	FilyDocumentTemplate = NULL ;		// no functions setup
	//FilyUpdateRibbonTab = NULL ;		// no functions setup
	
	if (filename != _T(""))
		LoadDLL(filename) ;
}

CDocumentsWrapper::~CDocumentsWrapper()
{
	// release any loaded DLL
	if (m_DLLhInstance != NULL)
		FreeLibrary(m_DLLhInstance) ;		// release library
}


bool CDocumentsWrapper::LoadDLL(CString filename)
{
	m_FileName = filename ;
	m_DLLhInstance = AfxLoadLibrary(filename) ;

	if (m_DLLhInstance != NULL)
	{
		// get pointers to functions
		// add others here
		//FilyUpdateRibbonTab = (UPDATERIBBONTAB)GetProcAddress(m_DLLhInstance, "UpdateRibbonTab") ;
		FilyDocumentTemplate = (FILYDOCTEMPLATE)GetProcAddress(m_DLLhInstance, "FilyDocTemplate") ;
	}
	return (m_DLLhInstance != NULL) ;
}

bool CDocumentsWrapper::FreeDLL()
{
	// release any loaded DLL
	if (m_DLLhInstance != NULL)
	{
		FreeLibrary(m_DLLhInstance) ;		// release library
		m_DLLhInstance = NULL ;
		m_FileName = _T("") ;
		// kill any function pointers
		FilyDocumentTemplate = NULL ;
		//FilyUpdateRibbonTab = NULL ;		// no functions setup
	}
	return true ;
}

// GetMyMultiDocTemplate
CMyMultiDocTemplate* CDocumentsWrapper::GetMyMultiDocTemplate(void)
{
	if(FilyDocumentTemplate == NULL)
	{
		return NULL;		
	}
	return FilyDocumentTemplate();
}


// GetFileName


CString CDocumentsWrapper::GetFileName(void)
{
	TCHAR		m_szDrive[_MAX_DRIVE];
	TCHAR		m_szDir[_MAX_DIR];
	TCHAR		m_szExt[_MAX_EXT];
	TCHAR		m_szFname[_MAX_FNAME];
	_wsplitpath_s(m_FileName, m_szDrive, _MAX_DRIVE, m_szDir, 
		_MAX_DIR, m_szFname, _MAX_FNAME, m_szExt, _MAX_EXT );
	
	CString file = m_szFname;
	//file += _T(".");
	file += m_szExt;
	return file;
}
